package com.cuitrip.business.user;

import android.content.Intent;
import android.app.Activity;
import android.os.Bundle;

import com.cuitrip.business.tripservice.model.ServiceInfo;
import com.cuitrip.business.user.model.CtUserInfo;
import com.cuitrip.service.R;
import com.lab.app.BaseActivity;
import com.lab.app.BaseFragment;
import com.lab.app.customui.CustomUiConfig;
import com.lab.app.customui.CustomUiFragmentActivity;

/**
 * Created by sheena on 16/5/13.
 */
public class CompleteBasicUserInfoActivity extends CustomUiFragmentActivity {

    private ServiceInfo mServiceInfo;
    private CtUserInfo mUserInfo;

    public static final int TYPE_BASIC_INFO=0;
    public static final int TYPE_MOBILE=1;
    public static final int TYPE_ID=2;
    public static final String KEY_TYPE="key_type";
    private int type;

    public static void startActivity(Activity activity, ServiceInfo serviceInfo, CtUserInfo userInfo,int type){
        Intent intent = new Intent(activity,CompleteBasicUserInfoActivity.class);
        intent.putExtra(ServiceInfo.KEY,serviceInfo);
        intent.putExtra(CtUserInfo.KEY,userInfo);
        intent.putExtra(KEY_TYPE,type);
        activity.startActivity(intent);
    }

    public static void startActivity(BaseFragment fragment,ServiceInfo serviceInfo,CtUserInfo userInfo,int type){
        Intent intent = new Intent(fragment.getHostActivity(),CompleteBasicUserInfoActivity.class);
        intent.putExtra(ServiceInfo.KEY,serviceInfo);
        intent.putExtra(CtUserInfo.KEY,userInfo);
        intent.putExtra(KEY_TYPE,type);
        fragment.startActivity(intent);
    }

    @Override
    public boolean initCloseTopBar() {
        return true;
    }

    @Override
    public CustomUiConfig initCustomUiConfig() {
        return null;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        if (getIntent() == null) {
            super.onCreate(savedInstanceState, R.layout.page_container_layout);
            return;
        }
        if(getIntent().hasExtra(ServiceInfo.KEY)){
            mServiceInfo = (ServiceInfo) getIntent().getSerializableExtra(ServiceInfo.KEY);
        }
        if (getIntent().hasExtra(CtUserInfo.KEY)){
            mUserInfo = (CtUserInfo) getIntent().getSerializableExtra(CtUserInfo.KEY);
        }

        if (getIntent().hasExtra(KEY_TYPE)){
            type = getIntent().getIntExtra(KEY_TYPE, -1);
        }
        super.onCreate(savedInstanceState, R.layout.page_container_layout);
    }

    @Override
    public void initView() {
        CompleteInsiderInfoFragment completeInsiderInfoFragment = CompleteInsiderInfoFragment.newInstance(mServiceInfo, mUserInfo);
        VerifyUserMoblieFragment verifyUserMoblieFragment = VerifyUserMoblieFragment.newInstance(mServiceInfo,mUserInfo);
        VerifyIDFragment verifyIDFragment = VerifyIDFragment.newInstance(mServiceInfo,mUserInfo);
        switch (type){
            case TYPE_BASIC_INFO:
                openFragment(completeInsiderInfoFragment,R.id.container,CompleteInsiderInfoFragment.class.getName(),false);
                break;

            case TYPE_MOBILE:
                openFragment(verifyUserMoblieFragment,R.id.container,VerifyUserMoblieFragment.class.getName(),false);
                break;

            case TYPE_ID:
                openFragment(verifyIDFragment,R.id.container,VerifyIDFragment.class.getName(),false);
                break;

            default:
                openFragment(completeInsiderInfoFragment,R.id.container,CompleteInsiderInfoFragment.class.getName(),false);
                break;

        }
    }

    @Override
    public void onBackPressed() {
        return;
    }
}
